package com.zsc.wxapp.controller.admin;

import com.zsc.wxapp.entity.dto.AdminAnnouncementDTO;
import com.zsc.wxapp.entity.dto.AnnouncementDTO;
import com.zsc.wxapp.entity.vo.AdminAnnouncementVO;
import com.zsc.wxapp.entity.vo.AnnouncementListVO;
import com.zsc.wxapp.entity.vo.AnnouncementVO;
import com.zsc.wxapp.result.Result;
import com.zsc.wxapp.services.AnnouncementService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.List;

@RestController
@RequestMapping("/api/wxapp/admin/announcement")
//@Api(tags = "公告相关接口")
@Slf4j
public class AdminAnnouncementController {

    @Resource
    private AnnouncementService announcementService;

    /**
     * 添加公告
     *
     * @param announcementDTO 公告信息
     * @return String
     */
    @PostMapping("/add")
    @ApiOperation("添加公告")
    public Result<String> add(AnnouncementDTO announcementDTO) throws IOException {
        log.info("添加公告:{}", announcementDTO);
        return Result.success(announcementService.add(announcementDTO));
    }


    @PostMapping("/update")
    @ApiOperation("修改公告")
    public Result<String> update(AdminAnnouncementDTO announcementDTO) throws IOException {
        log.info("修改公告:{}", announcementDTO);
        return Result.success(announcementService.update(announcementDTO));
    }
    /**
     * 删除公告
     *
     * @param ids 公告id
     * @return String
     */
    @DeleteMapping("/delete")
    @ApiOperation("删除公告")
    public Result<String> delete(@RequestParam("ids") List<Integer> ids) {
        log.info("删除公告:{}", ids);
        return Result.success(announcementService.delete(ids));
    }

    /**
     * 获取所有公告
     *
     * @return List<AnnouncementVO>
     */
    @GetMapping("/get")
    @ApiOperation("根据key获取该分类的所有公告")
//    @ApiImplicitParam(name = "type", value = "公告类型", required = true, dataTypeClass = Integer.class)
    public Result<List<AnnouncementListVO>> getAll() {
        return Result.success(announcementService.get());
    }

    /**
     * 获取公告详情
     *
     * @param id 公告id
     * @return AnnouncementVO
     */
    @GetMapping("/getById/{id}")
    @ApiOperation("获取公告详情")
//    @ApiImplicitParam(name = "id", value = "公告id", required = true, dataTypeClass = Integer.class)
    public Result<AdminAnnouncementVO> getById(@PathVariable Integer id) {
        log.info("获取公告详情,id:{}", id);
        return Result.success(announcementService.getListById(id));
    }
}
